from rest_framework.viewsets import ModelViewSet
from meiduo_admin.specs.spec_serializers import SPUSpecViewSerializer,SpecViewSerializer,SpecOptionsSerializer
from goods.models import SPUSpecification,SpecificationOption
from meiduo_admin.my_paginate import MyPageNuberPagination
from rest_framework.generics import ListAPIView


#规格管理
class SPUSpecViewSet(ModelViewSet):
    pagination_class = MyPageNuberPagination
    serializer_class=SPUSpecViewSerializer
    queryset = SPUSpecification.objects.all()

#规格选项管理
class SpecViewSet(ModelViewSet):
    pagination_class = MyPageNuberPagination
    serializer_class = SpecViewSerializer
    queryset = SpecificationOption.objects.all()

#新增规格选项
class SpecOptions(ListAPIView):
    serializer_class = SpecOptionsSerializer
    # queryset = SPUSpecification.objects.all()
    def get_queryset(self):
        queryset=SPUSpecification.objects.all()
        for spec in queryset:
            spec.name="{}-{}".format(spec.spu.name,spec.name)
        return queryset
